<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    </head>
    <body>
        <center>
            <h2 style="margin-top:80;">IOS JSBridge Demo</h2>
        </center>
        <center>
            <p id="text"></p>
        </center>
        <center>
            <center>
                <br />
                <center>
                    <p><a href="#" id="get">GET</a></p>
                    <p><a href="#" id="get_cache">GET（cache）</a></p>
                    <p><a href="#" id="post">POST</a></p>
                    <p><a href="#" id="post_cache">POST（cache）</a></p>
                    <p><a href="#" id="cancel_all_request">cancelAllRequest</a></p>
                    <p><a href="#" id="remove_cache_key">removeCache(Key)</a></p>
                    <p><a href="#" id="remove_cache_all">removeCache(All)</a></p>
                    <h2 style="margin-top:80;">xf audio</h2>
                    <p><a href="#" id="xf_build">build</a></p>
                    <p><a href="#" id="xf_start">start</a></p>
                    <p><a href="#" id="xf_stop">stop</a></p>
                    <p><a href="#" id="xf_dealloc">dealloc</a></p>
                    <center>
                        <br />
                    </center>
                </center>
            </center>
        </center>
        <script>
            function setupWebViewJavascriptBridge(callback) {
                if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
                if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
                window.WVJBCallbacks = [callback];
                var WVJBIframe = document.createElement('iframe');
                WVJBIframe.style.display = 'none';
                WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
                document.documentElement.appendChild(WVJBIframe);
                setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
            }
        
        setupWebViewJavascriptBridge(function(bridge) {
                                   
                                     
                                     
                                     document.getElementById('get').onclick = function() {
                                     bridge.callHandler('network-get', {url:'http://playschool.go.c2d.me/api/test/ios/get'}, function(response) {
                                                        document.getElementById('text').innerText = JSON.stringify(response);
                                                        })
                                     };
                                     document.getElementById('get_cache').onclick = function() {
                                     bridge.callHandler('network-get', {url:'http://playschool.go.c2d.me/api/test/ios/get',cacheKey:'88888888'}, function(response) {
                                                        document.getElementById('text').innerText = JSON.stringify(response);
                                                        })
                                     };
                                     
                                     
                                     document.getElementById('post').onclick = function() {
                                     bridge.callHandler('network-post', {url:'http://playschool.go.c2d.me/api/test/ios/get',params:{username:'wdh',password:'123'}}, function(response) {
                                                        document.getElementById('text').innerText = JSON.stringify(response);
                                                        })
                                     };
                                     document.getElementById('post_cache').onclick = function() {
                                     bridge.callHandler('network-post', {url:'http://playschool.go.c2d.me/api/test/ios/get',cacheKey:'88888888',params:{username:'wdh',password:'123'}}, function(response) {
                                                        document.getElementById('text').innerText = JSON.stringify(response);
                                                        })
                                     };
                                     
                                     //取消所有请求
                                     document.getElementById('cancel_all_request').onclick = function() {
                                     bridge.callHandler('network-operation', {operation:'cancel_all_request'}, function(response) {
                                                        document.getElementById('text').innerText = response;
                                                        })
                                     };
                                     //移除指定缓存
                                     document.getElementById('remove_cache_key').onclick = function() {
                                     bridge.callHandler('network-operation', {operation:'remove_cache_key',cacheKey:'cacheKey'}, function(response) {
                                                        document.getElementById('text').innerText = response;
                                                        })
                                     };
                                     //移除所有缓存
                                     document.getElementById('remove_cache_all').onclick = function() {
                                     bridge.callHandler('network-operation', {operation:'remove_cache_all'}, function(response) {
                                                        document.getElementById('text').innerText = response;
                                                        })
                                     };
                                     
                                     //讯飞语音
                                     document.getElementById('xf_build').onclick = function() {
                                     bridge.callHandler('xf-helper', {operation:'build'}, function(response) {
                                                        document.getElementById('text').innerText = response;
                                                        })
                                     };
                                     //供原生调用
                                     bridge.registerHandler('xf-result', function(data, responseCallback) {
                                                            if(data.success == "true"){
                                                            document.getElementById('text').innerText = "匹配成功"+data.results;
                                                            }else{
                                                            document.getElementById('text').innerText = "匹配失败";
                                                            }
                                                            });
                                     
                                    
                                     
                                     document.getElementById('xf_start').onclick = function() {
                                     bridge.callHandler('xf-helper', {operation:'start'}, function(response) {
                                                        document.getElementById('text').innerText = "录音中。。。";
                                                        })
                                     };
                                     
                                     document.getElementById('xf_stop').onclick = function() {
                                     bridge.callHandler('xf-helper', {operation:'stop'}, function(response) {
                                                        document.getElementById('text').innerText = "已停止录音";
                                                        })
                                     };
                                     
                                     document.getElementById('xf_dealloc').onclick = function() {
                                     bridge.callHandler('xf-helper', {operation:'dealloc'}, function(response) {
                                                        document.getElementById('text').innerText = "释放内存成功";
                                                        })
                                     };
                                     
                                     
                                     
                                     });
                                     
                                     
                                     
                                     
            </script>   
    </body>
</html>
